package com.cheng.example.geektime.designpatterns.j56.apply;

import java.util.ArrayList;
import java.util.List;

public class UserController {
    private UserService userService=new UserService(); //依赖注入

    private List<RegObserver> regObservers = new ArrayList<>();

    //一次性设置好，之后也不可能动态的修改
    public void setRegObservers(List<RegObserver> observers) {
        regObservers.addAll(observers);
    }

    public Long register(String telephone, String password) {
        long userId = userService.register(telephone, password);
        for (RegObserver observer : regObservers) {
            observer.handleRegSuccess(userId);
        }
        return userId;
    }


    public static void main(String[] args) {

        UserController userController = new UserController();
        List<RegObserver> regObservers = new ArrayList<>();
        regObservers.add(new RegNotificationObserver());
        regObservers.add(new RegPromotionObserver());
        userController.setRegObservers(regObservers);

        userController.register("17513137853", "123456");
    }


}
